package com.eric.controller;


import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.util.SaResult;
import com.eric.domain.po.User;
import com.eric.domain.vo.UserVo;
import com.eric.service.*;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 新哥
 * @since 2024-02-12
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
@CrossOrigin

public class UserController {
    private final PermissionService permissionService;
    private final RolesService rolesService;
    private final UserService userService;
    
    @RequestMapping
//    使用注解鉴权，需要在SaTokenConfigure配置类中，加入SaInterceptor拦截器才能生效
//    SaCheckRole是检查角色
    @SaCheckRole(value = {"normal"})
//    @SaCheckPermission(value = {"user.search","user.add","user.visit"})
    public Object getOneUserById(Integer id){
        return userService.getOneById(id);
    }

    @PostMapping("save")
    @ResponseBody
    @SaCheckRole(value = {"admin"})
     public SaResult saveOneLoginUser(User newUser, MultipartFile file, HttpServletRequest req){

        return userService.saveOne(newUser,file,req);

    }


}
